
PYTHON=`which python`
DESTDIR=/
BUILDIR=$(CURDIR)/debian/tichy
PROJECT=tichy
VERSION=1.1.0

all:
	@echo "make build - Build tichy"
	@echo "make install - Install on local system"
	@echo "make buildrpm - Generate a rpm package"
	@echo "make builddeb - Generate a deb package"
	@echo "make clean - Get rid of scratch and byte files"
	@echo "make buildext - Compile the c extensions in place"
	
build:
	$(PYTHON) setup.py build

sdist:
	$(PYTHON) setup.py sdist

buildext:
	$(PYTHON) setup.py build_ext --inplace
	
install:
	$(PYTHON) setup.py install --root $(DESTDIR) $(COMPILE)

buildrpm:
	$(PYTHON) setup.py bdist_rpm --post-install=rpm/postinstall --pre-uninstall=rpm/preuninstall

builddeb:
	mkdir -p ${BUILDIR}
	DESTDIR=$(BUILDIR) dpkg-buildpackage -rfakeroot

# This rule is very ugly. Use this at your own risks.  It creates the
# ipk file for SHR without using openembedded.  It assumes the
# directory ./tichy/guic/ contains the .so file compiled using the
# toolchain.
buildipkg:
	mkdir -p ipkg/CONTROL
	python setup.py install --prefix=ipkg/usr/
	mv ipkg/usr/lib/python2.5 ipkg/usr/lib/python2.6
	cp tichy/guic/*.so ipkg/usr/lib/python2.6/site-packages/tichy/guic/
	cp debian/tichy/DEBIAN/control ipkg/CONTROL/
	# set Architecture to armv4t
	sed -i 's/Architecture:.*$$/Architecture: armv4t/g' ipkg/CONTROL/control
	# add Source field
	echo "Source: tichy" >> ipkg/CONTROL/control
	# replace different packages names
	sed -i 's/python-yaml/python-pyyaml/g' ipkg/CONTROL/control
	sed -i 's/python-gobject/python-pygobject/g' ipkg/CONTROL/control
	# remove dep of packages that don't exist in SHR
	sed -i 's/, python-xlib//g' ipkg/CONTROL/control
	sed -i 's/, gstreamer0.10-plugins-base//g' ipkg/CONTROL/control
	sed -i 's/, ttf-arphic-bkai00mp//g' ipkg/CONTROL/control
	# create the package
	cd ipkg; ipkg-build .

clean:
	$(PYTHON) setup.py clean
	$(MAKE) -f $(CURDIR)/debian/rules clean
	rm -rf build/ MANIFEST
	rm -rf ipkg/usr
	find . -name '*.pyc' -delete
	find . -name '*.o' -delete
	find . -name '*.so' -delete
